package cn.heima.com;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class StduentDemo {
    /*
    * 1.分析以下需求，并用代码实现：
	    (1)定义一个学生类Student，包含属性：姓名(String name)、年龄(int age)
	    (2)定义Map集合，用Student对象作为key，用字符串(此表示表示学生的住址)作为value
	    (3)利用四种方式遍历Map集合中的内容，格式：key::value
    * */
    public static void main(String[] args) {
        Map<Student, String> map = new HashMap<>();
        Student student1 = new Student("xiaoming", 22);
        Student student2 = new Student("xiaohuang", 23);
        Student student3 = new Student("xiaoshuai", 24);
        map.put(student1, "长沙");
        map.put(student2, "深圳");
        map.put(student3, "武汉");

        Set<Student> students = map.keySet();
        for (Student student : students) {
            String str = map.get(student);
            System.out.println(student.getName()+"\t"+student.getAge()+"\t"+str);
        }
        System.out.println("---------------------------------");
        Iterator<Student> it = students.iterator();
        while (it.hasNext()){
            Student next = it.next();
            String str = map.get(next);
            System.out.println(next.getName()+"\t"+next.getAge()+"\t"+str);
        }
        System.out.println("--------------------------------");
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            System.out.println(entry.getKey()+"-->"+entry.getValue());
        }
        System.out.println("---------------------------------");
        Iterator<Map.Entry<Student, String>> its = entries.iterator();
        while(its.hasNext()){
            Map.Entry<Student, String> next = its.next();
            Student key = next.getKey();
            String value = next.getValue();
            System.out.println(key+"-->"+value);
        }
    }
}
